package com.cee.admin.modules.cockpit.controller;

import com.cee.admin.common.BaseController;
import com.cee.common.web.result.Result;
import com.cee.domain.common.entity.BasePrincipal;
import com.cee.domain.modules.cockpit.vo.CockpitEmissionDataVo;
import com.cee.domain.modules.sys.entity.SysFrontUser;
import com.cee.domain.modules.sys.entity.User;
import com.cee.ds.common.utils.BasePrincipalUtils;
import com.cee.ds.modules.ece.service.IIndustrialParksService;
import com.cee.ds.modules.sys.service.ISysFrontUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  园区驾驶舱控制器
 * </p>
 *
 * @author: lzj
 * @since: 2025-05-12
 */
@RestController
@RequestMapping("/api/park/cockpit")
@Tag(name = "园区驾驶舱")
public class ParkCockpitController extends BaseController {

    @Autowired
    private IIndustrialParksService industrialParksService;

    @Autowired
    private ISysFrontUserService sysFrontUserService;

    @Operation(summary = "根据当前登录用户获取当前园区管理员所管理的园区图片")
    @GetMapping("/getImageById")
    public Result<String> getImageInfo() {
        User user = BasePrincipalUtils.currentUser();
        return success(industrialParksService.getImageById(user.getManageParkId()));
    }

    public List<SysFrontUser> getSysFrontUserList() {
        User user = BasePrincipalUtils.currentUser();
        return sysFrontUserService.getByParkId(user.getManageParkId());
    }

    @Operation(summary = "当前登录用户管理园区数据统计")
    @GetMapping("/consumptionEmissionStats")
    public Result<CockpitEmissionDataVo> consumptionEmissionStats(){
        return success(industrialParksService.consumptionEmissionStats(getSysFrontUserList()));
    }
}